// Array *Rep*resentation of number literal; recursive type testing
type Rep<N, A extends any[] = []> = A["length"] extends N
  ? A
  : Rep<N, [0, ...A]>;
// *Add*ition of two literals by concatenating their representations
type Add<L, R> = [...Rep<L>, ...Rep<R>]["length"];
// *Sub*traction of two literals; recursive type testing
type Sub<L, R, A extends any[] = []> = L extends R
  ? A["length"]
  : Sub<L, Add<R, 1>, [0, ...A]>;

type Fibonacci<T> = T extends 0
  ? 0
  : T extends 1
  ? 1
  : Add<Fibonacci<Sub<T, 2>>, Fibonacci<Sub<T, 1>>>;
